找传奇、传世资源到传世资源站!

C# 通过正则采集某网站的图片数据

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Text;using System.Text.RegularExpressions;using System.Threading.Tasks;namespace 正则提取{ class Program { private static HttpWebRequest myHttpWebRequest; static void Main(string[] args) { //采集部分 Console.WriteLine("编号"); int t = int.Parse(Console.ReadLine()); Console.WriteLine("开始页"); int i = int.Parse(Console.ReadLine()); Console.WriteLine("结束页"); int n = int.Parse(Console.ReadLine()); for (int x = i; i < n; i ) { string strURL = "https://bbs.xd.com/thread-" t "-" i "-1.html"; myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL); myHttpWebRequest.Timeout = 20 * 1000; //连接超时 myHttpWebRequest.Accept = "text / html,application / xhtml xml,application / xml; q = 0.9,*/*;q=0.8"; myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;)"; //myHttpWebRequest.Headers.Add("Cookie", "UM_distinctid = 15b917f117652c - 0e0f802cc2344a8 - 13646e4a - 1fa400 - 15b917f117751c; CNZZDATA1254852923 = 818605592 - 1492791763 - http% 253A % 252F % 252Fsgk.fbisb.com % 252F % 7C1492850579"); //myHttpWebRequest.Host = "s.70sec.com"; //myHttpWebRequest.Referer = "upload/attach/202206/img/13261_54196.png"); if (index > -1) { // Console.WriteLine(line); Match mc = Regex.Match(line, @"(?<=nowrap;""> )(.*?)(?=<img class=""uc_platform_icon"" src=""static/image/siteicon/v4/xd.png)", RegexOptions.Multiline); string href1 = mc.Groups[1].Value; Console.WriteLine("{1}获取到内容{0}:", x,href1); string href = href1 "\r\n"; StreamWriter sw = File.AppendText("1.txt"); sw.Write(href); sw.Close(); } } } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复